
// 获取应用实例
const app = getApp()
import Toast from '@vant/weapp/toast/toast';
Page({
  data: {
      selected:'',
      dealList:[],
      objCard:{}
  },
  getCurrentDate(){
    var dd = new Date();  
    var y = dd.getFullYear(); 
    var m = dd.getMonth()+1;//获取当前月份的日期 
    var d = dd.getDate(); 
    //判断 月
    if(m < 10){
      m = "0" + m;
    }else{
      m = m;
    }
    return y+m; 
  },
  clickItem(item){
    const id = item.currentTarget.dataset.item.dateValue
    this.setData({
        selected: id
    })
    this.getData(this.data.cardId,id)

  },
  onLoad(option){
    this.selectComponent("#loading").show()
    const cardId = option.cardId;
    const that = this;
    const time = that.getCurrentDate()
    this.setData({
        selected: time,
        cardId:cardId
    })
    app.getLogUser(function () {
        that.getData(cardId,time)
    })
  },
  getData(cardId,monthId){
    const that = this
    wx.request({
        url: app.globalData.apiUrlNew + 'Mini/BalUpdated.ashx?action=listRest',
        data: {
          cardId:cardId,
          monthId:monthId
        },
        dataType: 'json',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(resroom) {
          console.log(resroom.data)
          var result = resroom.data;
          if (result.getNum == 0) {
            that.setData({
                objCard:result.objCard,
                dtDate:result.dtDate,
                dealList: result.dtRest
            })
          } else {
              Toast({
                type: 'fail',
                message: '1' + result.getMsg,
                onClose: () => {
                    wx.redirectTo({
                        url: '../index/index?cardId='+cardId,
                    })
                  },
              })
          }
        },
        fail(resfail) {
          Toast.fail(resfail.data)
        }
      }) 
      this.selectComponent("#loading").hide()
  }
})
